//
//  XDPhotoTextViewController.m
//  Le way walkers
//
//  Created by POP-mac on 15/5/14.
//  Copyright (c) 2015年 LTXZ. All rights reserved.
//

#import "XDPhotoTextViewController.h"
#import "XDDetailsViewController.h"

@interface XDPhotoTextViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, assign) BOOL pass;
@property (nonatomic, retain) UIButton *button;
@property (nonatomic, assign) CGFloat jiao;
@end

@implementation XDPhotoTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setBackgroundColor:[UIColor blackColor]];
    [self.tabBarController.tabBar setHidden:YES];
    self.navigationController.navigationBarHidden = YES;
    [self creatCollection];
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.button setBackgroundImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    self.button.alpha = 0.8;
    [self.button setFrame:CGRectMake(20, 20, 32, 32)];
    [self.button addTarget:self action:@selector(closes) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];
    NSLog(@"/*/*/*%ld", self.number_photo);
    NSLog(@"%@", [[self.photo_text_details objectAtIndex:0] photo]);
    
}

- (void)closes
{
    [self.delegate get:self.number_photo];
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)creatCollection
{
    self.flowLayout = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    self.flowLayout.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
    self.flowLayout.minimumInteritemSpacing = 10;
    self.flowLayout.minimumLineSpacing = 0;
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collection = [[[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.flowLayout] autorelease];
    [self.collection setPagingEnabled:YES];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.contentOffset = CGPointMake(self.view.frame.size.width * self.number_photo, 0);
    [self.view addSubview:self.collection];
    [self.collection registerClass:[XDPhotoTextCollectionViewCell class] forCellWithReuseIdentifier:@"my"];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    XDPhotoTextCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"my" forIndexPath:indexPath];
    
    XDPhotoText *m = self.photo_text_details[indexPath.row];
    cell.model = m;
//    self.title = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
    cell.scroll.contentOffset = CGPointMake(0, 0);
    return cell;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.number_photo = self.collection.contentOffset.x / self.view.frame.size.width;
    
    NSLog(@"%ld", self.number_photo);
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.photo_text_details.count;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"12");
    self.jiao = self.jiao + 1.5708;
    [UIView animateWithDuration:0.8 animations:^{
        self.button.transform = CGAffineTransformMakeRotation(self.jiao);
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
